// This file contains user-related API functions
import type { 
  RegisterData, RegisterResponses,
  LogoutData, LogoutResponses,
  LoginData, LoginResponses,
  DeleteAccountData, DeleteAccountResponses,
  GetUserByIdData, GetUserByIdResponses,
  GetCurrentUserData, GetCurrentUserResponses,
  CheckLoginData, CheckLoginResponses
} from './userTypes';
import { client as _heyApiClient } from '../../api/client.gen';
import type { Options } from '../common/apiTypes';

/**
 * 用户注册
 * 新用户注册接口，需要用户名、邮箱和密码
 */
export const register = <ThrowOnError extends boolean = false>(options: Options<RegisterData, ThrowOnError>) => {
    return (options.client ?? _heyApiClient).post<RegisterResponses, unknown, ThrowOnError>({
        url: '/api/user/register',
        ...options,
        headers: {
            'Content-Type': 'application/json',
            ...options.headers
        }
    });
};

/**
 * 用户登出
 * 用户登出接口，清除会话信息
 */
export const logout = <ThrowOnError extends boolean = false>(options?: Options<LogoutData, ThrowOnError>) => {
    return (options?.client ?? _heyApiClient).post<LogoutResponses, unknown, ThrowOnError>({
        url: '/api/user/logout',
        ...options
    });
};

/**
 * 用户登录
 * 用户登录接口，支持用户名或邮箱登录
 */
export const login = <ThrowOnError extends boolean = false>(options: Options<LoginData, ThrowOnError>) => {
    return (options.client ?? _heyApiClient).post<LoginResponses, unknown, ThrowOnError>({
        url: '/api/user/login',
        ...options,
        headers: {
            'Content-Type': 'application/json',
            ...options.headers
        }
    });
};

/**
 * 注销用户账号
 * 永久删除当前用户的账号，需要验证密码
 */
export const deleteAccount = <ThrowOnError extends boolean = false>(options: Options<DeleteAccountData, ThrowOnError>) => {
    return (options.client ?? _heyApiClient).post<DeleteAccountResponses, unknown, ThrowOnError>({
        url: '/api/user/delete-account',
        ...options
    });
};

/**
 * 根据ID获取用户信息
 * 根据用户ID获取用户详细信息
 */
export const getUserById = <ThrowOnError extends boolean = false>(options: Options<GetUserByIdData, ThrowOnError>) => {
    return (options.client ?? _heyApiClient).get<GetUserByIdResponses, unknown, ThrowOnError>({
        url: '/api/user/{userId}',
        ...options
    });
};

/**
 * 获取当前用户信息
 * 获取当前登录用户的详细信息
 */
export const getCurrentUser = <ThrowOnError extends boolean = false>(options?: Options<GetCurrentUserData, ThrowOnError>) => {
    return (options?.client ?? _heyApiClient).get<GetCurrentUserResponses, unknown, ThrowOnError>({
        url: '/api/user/current',
        ...options
    });
};

/**
 * 检查登录状态
 * 检查当前用户是否已登录
 */
export const checkLogin = <ThrowOnError extends boolean = false>(options?: Options<CheckLoginData, ThrowOnError>) => {
    return (options?.client ?? _heyApiClient).get<CheckLoginResponses, unknown, ThrowOnError>({
        url: '/api/user/check-login',
        ...options
    });
};